VAR threshold profiles ====================== A threshold VAR with a calibrated cutoff has known regimes, so its posterior mode and its marginal data density given the cutoff come in closed form (see :doc:`Switching VARs with known regimes`). ``threshold_profile`` scores many candidate values of the cutoff in one call:: out = threshold_profile(m, 'thr', grid, 'data', db, 'estim_var_prior', prior, ...); For each candidate it returns the mode, the log posterior at the mode and the log marginal data density given the cutoff, :math:`\log p(Y \mid \mathit{thr})`, without estimating the model once per candidate. The grid and the choice among the candidates are the user's. .. contents:: :local: :depth: 1 The call -------- ``threshold_profile(obj, parameter_name, grid, varargin)`` takes * ``obj``: an ``rfvar_model`` or a ``prfvar_model`` with more than one regime; * ``parameter_name``: a parameter of the transition probabilities that is not estimated, such as the cutoff ``thr`` of ``hard_threshold(pinfobs,thr,0)``; * ``grid``: its candidate values, finite, in any order; * ``varargin``: the arguments of ``estimate`` (``'data'``, ``'estim_var_prior'``, the estimation window, ``solve_check_stability``, ...). The problem is built once, as ``estimate`` would build it. A candidate costs one evaluation of the model, which gives its regime path, and nothing else is rebuilt. Candidates with the same path are one partition of the sample: its mode and its marginal data density are computed once and reported for each of its candidates. Reordering the grid reorders the rows of the results (and renumbers the partitions). The output ---------- With :math:`J` candidates, :math:`h` regimes, :math:`n` variables and :math:`K` regressors, ``out`` has the fields .. list-table:: :header-rows: 1 :widths: 34 66 * - Field - Content * - ``parameter``, ``grid`` - as given (``grid`` is :math:`J \times 1`) * - ``status`` - :math:`J \times 1` cell: ``''``, or why the candidate has no result * - ``partition_id`` - :math:`J \times 1`: the partition of each candidate, numbered in the order of first appearance (0 without a known path) * - ``n_partitions``, ``paths``, ``first_scored`` - the number of distinct partitions, their regime paths over the likelihood periods (one column each), and the first period that is scored * - ``occupancy`` - :math:`J \times h`: the number of scored periods in each regime * - ``log_post`` - :math:`J \times 1`: the log posterior kernel at the mode, the ``log_post`` of ``estimate`` * - ``log_marginal_data_density``, ``log_marginal_data_density_reason`` - :math:`J \times 1` and :math:`J \times 1` cell: the closed-form log marginal data density given the path, in nats, and ``''``, a label or the reason it is NaN (no ``_closed_form`` suffix, unlike the fields of ``estimate``) * - ``B``, ``Sigma`` - :math:`n \times K \times h \times J` and :math:`n \times n \times h \times J`: the mode. Rows are the equations, columns the constant, the deterministic variables and the lags, the variables in alphabetical order * - ``calibration`` - :math:`J \times 1` cell: the mode as a struct of parameter values, as ``set(m, 'parameters', ...)`` takes it * - ``iterations``, ``score`` - the passes of the alternation and the scaled score at the mode Statuses and errors ------------------- A candidate without a result has NaN in its numerical fields and its reason in ``status``; the other candidates are unaffected. For example: * ``the conditional of covariance (regimes 2) is not an exact normal or inverse-Wishart``: regime 2 is empty and the prior has no proper density on the covariance (``minnesota``); * ``the kernel rejects a conditional mode (return code 25)``: under ``solve_check_stability = true``, a pass of the alternation reaches a VAR that is not stable. With the model of the example below and RISE's defaults, the cutoffs 0.2 and 0.25, which leave 2 quarters in regime 1, get this status; without the stability check they have their values. A candidate can have a mode and no marginal data density: its ``log_marginal_data_density`` is NaN with the reason, as listed in :doc:`Switching VARs with known regimes`. These are errors: .. list-table:: :header-rows: 1 :widths: 46 54 * - Identifier - When * - ``bvar_known_regime_profile:estimated`` - the parameter is estimated: the regimes of a candidate are known only when its value is given * - ``bvar_known_regime_profile:unknownParameter`` - the model has no such parameter * - ``bvar_known_regime_profile:oneRegime`` - the model has one regime * - ``bvar_known_regime_profile:pathNotKnown`` - the regimes are not known from the data at a candidate tried before the problem is built: a latent chain, or an uncertain path, for example with ``hard_threshold``'s default floor of :math:`10^{-10}` (which ``threshold_chains`` writes); once the problem is built, an uncertain path is a status * - ``bvar_known_regime_profile:noCandidate`` - no candidate has a known path with closed-form conditionals * - ``threshold_profile:model``, ``threshold_profile:notVectorized`` - the model is not a reduced-form VAR, or is an array of models An empty grid, or one with a NaN or an infinite value, fails the argument validation. Reading the profile ------------------- * Every candidate scores the same periods: only the partition changes. The values of different candidates are therefore comparable. * Each value conditions on its cutoff. With prior probabilities :math:`\pi_{j}` on the grid, the posterior probability of candidate :math:`j` is proportional to :math:`\pi_{j}\, p(Y \mid \mathit{thr}_{j})`, and :math:`\log \sum_{j} \pi_{j}\, p(Y \mid \mathit{thr}_{j})` is the log marginal data density of the threshold VAR whose cutoff has that prior. Candidates of one partition have equal values, so a uniform prior on the grid weighs a partition by its number of candidates. * A period whose threshold variable, as the chain reads it (here the inflation of the quarter before), equals the cutoff is in regime 1. A grid made of the distinct values of that variable over the scored periods therefore visits once each partition whose regime 1 is not empty. * Nothing is trimmed: an empty regime under a proper prior keeps the mode of its prior and adds 0 to the marginal data density, so a cutoff beyond the data gives the constant-parameter VAR's value. Keeping a share of the periods in each regime is the user's choice, through the grid. * Under the stability check or finite parameter bounds each value carries the label of :doc:`Closed-form marginal data density of VARs`. The values, the mode and ``log_post`` do not change, except at a candidate whose alternation reaches a VAR that is not stable: it gets a status (above). * To take the candidate with the largest exact value, leave out the statuses, the NaNs and the labels; ``max`` keeps the first of tied candidates:: valid = find(cellfun(@isempty, out.status) ... & cellfun(@isempty, out.log_marginal_data_density_reason) ... & isfinite(out.log_marginal_data_density)); [~, k] = max(out.log_marginal_data_density(valid)); best = valid(k); mb = set(m, 'parameters', struct('thr', out.grid(best))); An example ---------- The threshold VAR(1) of :doc:`Switching VARs with known regimes` (quarterly inflation and the federal funds rate in percent per quarter, 1966Q1-2004Q4, ``niw``, regime 2 when the inflation of the previous quarter is above ``thr``), profiled over 13 cutoffs with ``solve_check_stability = false`` and ``estim_prior_trunc = 0``:: out = threshold_profile(m, 'thr', (0.4:0.1:1.6).', 'data', db, ... 'estim_start_date', date2serial('1966Q1'), ... 'estim_end_date', date2serial('2004Q4'), ... 'estim_var_prior', prior, ... 'solve_check_stability', false, 'estim_prior_trunc', 0); .. list-table:: :header-rows: 1 :widths: 16 16 16 26 26 * - ``thr`` - regime 1 - regime 2 - log MDD - ``log_post`` * - 0.4 - 18 - 137 - -60.8299 - -1.9717 * - 0.5 - 33 - 122 - -54.6746 - 2.2380 * - 0.6 - 48 - 107 - -42.1703 - 14.2961 * - 0.7 - 61 - 94 - -39.2101 - 15.8903 * - 0.8 - 76 - 79 - -47.9022 - 4.8804 * - 0.9 - 84 - 71 - -48.1664 - 3.8128 * - 1.0 - 90 - 65 - -46.0661 - 5.4148 * - 1.1 - 99 - 56 - -44.7006 - 5.7527 * - 1.2 - 107 - 48 - -43.1164 - 6.3940 * - 1.3 - 113 - 42 - -54.4369 - -5.8291 * - 1.4 - 118 - 37 - -54.7302 - -6.7736 * - 1.5 - 125 - 30 - -50.6026 - -3.7926 * - 1.6 - 128 - 27 - -58.2736 - -12.0560 The 155 scored quarters (1966Q2-2004Q4) give 13 partitions. At the best cutoff of the grid, 0.7, ``estimate`` returns the same log marginal data density (-39.210139), the same ``log_post`` (15.890298) and the same mode. With a uniform prior on the grid, 0.7 has posterior probability 0.928, 0.6 0.048 and 1.2 0.019; the threshold VAR with that prior has a log marginal data density of -41.7005, against -71.3346 for the constant-parameter VAR on the same quarters. These probabilities belong to this grid: the cutoff 0.7061, between two of its points, scores higher still (below). In the run behind this page the 13 candidates took 7.0 seconds (0.54 seconds each, the build included), and one ``estimate`` at one cutoff, without its Hessian, 0.78 seconds; every candidate of this grid has a partition of its own, and so a solve of its own. At the default settings, four more candidates give .. list-table:: :header-rows: 1 :widths: 20 16 16 16 32 * - ``thr`` - regime 1 - regime 2 - partition - log MDD * - 0.7 - 61 - 94 - 1 - -39.2101 * - 0.7061 (a value of lagged inflation) - 62 - 93 - 2 - -37.8898 * - 0.7065 (between that value and the next) - 62 - 93 - 2 - -37.8898 * - 4.6608 (above the data) - 155 - 0 - 3 - -71.3346 each with the reason ``integral of the untruncated kernel; the estimated kernel is truncated by the stability check and finite parameter bounds``. The quarter whose lagged inflation is 0.7061 moves to regime 1 when the cutoff reaches it, the next two candidates share one partition, and the empty regime gives back the constant VAR. Under ``minnesota`` the cutoff above the data has the status ``the conditional of covariance (regimes 2) is not an exact normal or inverse-Wishart``, and ``thr = 1`` has its mode (``log_post`` -4.0740) and no marginal data density. The tutorial ``Estimation/var_threshold_profile/howto.m`` runs this example. The routine ----------- ``threshold_profile`` builds the model data with ``pull_objective`` and calls ``rise.engine.var.vartools.bvar_known_regime_profile(model_data, parameter_name, grid)``, which takes the model data directly.